getData()

function getData(keyword){
    let url = 'http://be.wj0325.top/roles'
    if(keyword){
        url=url+'?keyword='+keyword
    }
    let tr=$('[id^=role]');
    tr.remove();

    $.ajax({
        type:'get',
        url:url,
        success:function(res){
            res.forEach(item=>{
                let html = `
                        <tr id="role${item.id}">
                            <td>${item.id}</td>
                            <td>${item.rolename}</td>
                            <td>${item.email}</td>
                            <td>
                                <input type="button" value="编辑" onclick="btnEdit(${item.id})">
                                <input type="button" value="删除" onclick="btnDel(${item.id})">
                            </td>
                        </tr>`
                        let tbRole=$('#tbRole')
                        tbRole.append(html);
            })
        }
    })

}
function btnFilter() {
    let keyword = $('[name=keyword]').val();
    getData(keyword);
}


function btnAdd() {
    location.href = 'addOrEdit.html';
}

//编辑
function btnEdit(id) {
    location.href = 'addOrEdit.html?id=' + id;
}

function btnDel(id){
    if(confirm('你删除？')){
        $.ajax({
            type:'delete',
            url :'http://be.wj0325.top/roles/'+id,
            success:function(res){
                $('#role'+id).remove()
            }
        })
    }
}